﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;
using System.Text;
public partial class bgDate_HourValue : System.Web.UI.Page
{
    string repName;
    string unit;
    string time;
    string id;
    string qsrq;
    string jsrq;

    BLLData da = new BLLData();
    StringBuilder sb = new StringBuilder();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            repName = Request.QueryString["repName"];
            unit = Request.QueryString["uint"];
            time = Request.QueryString["time"];
            id = Request.QueryString["IDKEY"];

            this.hID.Value = id;
            this.hTime.Value = time;
            this.jz.Value = unit;

            DateTime dt = DateTime.Now;

            qsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 0:00:00");
            jsrq = DateTime.Parse(time).ToString("yyyy-MM-dd 23:59:59");

            if (DateTime.Parse(time) <= dt)
            {
                DataRow dr = da.RetDataRowByID(id);

                ArrayList list = da.RetValueHour(dr["参数名"].ToString(), dr["小时点"].ToString(), unit, dr["参数类型"].ToString(), qsrq, jsrq);

                string[] value = (string[])list[0];
                string[] date = (string[])list[1];
                string[] tj = (string[])list[2];

                if (value.Length > 0)
                {
                    for (int i = 0; i < 24; i++)
                    {
                        if (value[i] != null)
                        {
                            sb.Append("<tr>");

                            sb.AppendFormat("<td align='center'>{0}</td>", dr["参数名"].ToString());

                            sb.AppendFormat("<td align='center'>{0}</td>", dr["小时点"].ToString());

                            sb.AppendFormat("<td align='center'>{0}</td>", date[i]);

                            sb.AppendFormat("<td align='center'><input type=\"text\" id=\"txtValue" + i + "\" value='{0}' class=\"nvinput\" /></td>", value[i]);

                            if (tj[i] == "0")
                                sb.Append("<td align='center'><input type=\"checkbox\" id=\"chk" + i + "\" value=\"0\"  name=\"chk\" ></input></td>");//OnClick=\"chk()\"
                            else
                                sb.Append("<td align='center'><input type=\"checkbox\" id=\"chk" + i + "\" value=\"1\"  checked=\"true\" \"name=\"chk\"></input></td>");//OnClick=\"chk()\

                            sb.Append("</tr>");
                        }
                        else
                        {
                            sb.Append("<tr>");

                            sb.AppendFormat("<td align='center'>{0}</td>", dr["参数名"].ToString());

                            sb.AppendFormat("<td align='center'>{0}</td>", dr["小时点"].ToString());

                            sb.AppendFormat("<td align='center'>{0}</td>", DateTime.Parse(date[0].ToString()).ToShortDateString() + " " + i + ":00:00");

                            sb.AppendFormat("<td align='center'><input type=\"text\" id=\"txtValue" + i + "\" value='{0}' class=\"nvinput\" /></td>", "");

                            sb.Append("<td align='center'><input type=\"checkbox\" id=\"chk" + i + "\" value=\"0\" OnClick=\"chk()\" name=\"chk\" ></input></td>");

                            sb.Append("</tr>");
                        }
                    }
                }
                else
                    sb.Append("读取的日期内,无数据记录!");


                this.show.InnerHtml = sb.ToString();
            }
            else
            {
                Jscript.Alert("请选择正确日期！");
                this.Response.Write("<script language=javascript>window.close();</script>");
            }
        }
    }

    //保存
    protected void btnSave_Click(object sender, EventArgs e)
    {
        string[] val = new string[24];
        string[] bj = new string[24];

        string id = this.hID.Value;
        string time = this.hTime.Value;
        string unit = this.jz.Value;

        val[0] = this.Hidden1.Value;
        val[1] = this.Hidden2.Value;
        val[2] = this.Hidden3.Value;
        val[3] = this.Hidden4.Value;
        val[4] = this.Hidden5.Value;
        val[5] = this.Hidden6.Value;
        val[6] = this.Hidden7.Value;
        val[7] = this.Hidden8.Value;
        val[8] = this.Hidden9.Value;
        val[9] = this.Hidden10.Value;
        val[10] = this.Hidden11.Value;
        val[11] = this.Hidden12.Value;
        val[12] = this.Hidden13.Value;
        val[13] = this.Hidden14.Value;
        val[14] = this.Hidden15.Value;
        val[15] = this.Hidden16.Value;
        val[16] = this.Hidden17.Value;
        val[17] = this.Hidden18.Value;
        val[18] = this.Hidden19.Value;
        val[19] = this.Hidden20.Value;
        val[20] = this.Hidden21.Value;
        val[21] = this.Hidden22.Value;
        val[22] = this.Hidden23.Value;
        val[23] = this.Hidden24.Value;

        bj[0] = this.Hid25.Value;
        bj[1] = this.Hid26.Value;
        bj[2] = this.Hid27.Value;
        bj[3] = this.Hid28.Value;
        bj[4] = this.Hid29.Value;
        bj[5] = this.Hid30.Value;
        bj[6] = this.Hid31.Value;
        bj[7] = this.Hid32.Value;
        bj[8] = this.Hid33.Value;
        bj[9] = this.Hid34.Value;
        bj[10] = this.Hid35.Value;
        bj[11] = this.Hid36.Value;
        bj[12] = this.Hid37.Value;
        bj[13] = this.Hid38.Value;
        bj[14] = this.Hid39.Value;
        bj[15] = this.Hid40.Value;
        bj[16] = this.Hid41.Value;
        bj[17] = this.Hid42.Value;
        bj[18] = this.Hid43.Value;
        bj[19] = this.Hid44.Value;
        bj[20] = this.Hid45.Value;
        bj[21] = this.Hid46.Value;
        bj[22] = this.Hid47.Value;
        bj[23] = this.Hid48.Value;

        bool flag = da.RetIsTrueToSaveHours(id, unit, time, val, bj);

        if (flag == true)
            Jscript.AlertAndCloseWindow("保存成功!");
        else
            Jscript.Alert("保存失败!");

    }
}
